package com.situ.web.controller;

import com.situ.web.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/setCookie")
public class SetCookieServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("SetCookieServlet.service");

        //原来有session就返回，没有就创建session
        HttpSession session = req.getSession(true);
        session.setAttribute("user", new User());
        session.getAttribute("user");
        session.removeAttribute("user");

        Cookie cookie = new Cookie("goods", "IPhone");
        resp.addCookie(cookie);
    }

}
